<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
    <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
    <script type="text/javascript" src="/webjars/bootstrap/3.3.7/js/bootstrap.js"></script>
    <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
    <script src="/webjars/axios/0.19.0/dist/axios.js" type="text/javascript"></script>
</head>
<body>
<div id="vuebox">
    <div class="container" style="margin-top: 50px">
        <h1>学员信息列表</h1>
<!--        <div class="col-md-4 text-right">
            <a @click.prevent="addBook" class="btn btn-primary">新增电子图书</a>
        </div>-->
        <br/>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>编号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>年龄</th>
                <th>住址</th>
                <th>邮箱</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="item in stuList">
                <td><a href="#" @click.prevent="to_update_stu(item.sid)">{{item.sid}}</a></td>
                <td>{{item.sname}}</td>
                <td>{{item.sgender}}</td>
                <td>{{item.sage}}</td>
                <td>{{item.saddress}}</td>
                <td>{{item.semail}}</td>
            </tr>
            </tbody>
        </table>
        <br/>
    </div>

    <!--模态框-->
    <div class="modal" id="mymodal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button @click="hideModal" class="close" type="button">&times;</button>
                    <div class="modal-title">学员信息</div>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">

                        <!--id-->
                        <input type="hidden" v-model="new_stu.sid" id="sid">

                        <div class="form-group">
                            <label for="sname" class="col-sm-2 control-label">姓名</label>
                            <div class="col-sm-10">
                                <input v-model="new_stu.sname" id="sname" type="text" class="form-control" placeholder="请输入图书名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sgender" class="col-sm-2 control-label">年龄</label>
                            <div class="col-sm-10">
                                <input v-model="new_stu.sgender" id="sgender" type="text" class="form-control" placeholder="请输入图书摘要"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sage" class="col-sm-2 control-label">性别</label>
                            <div class="col-sm-10">
                                <input v-model="new_stu.sage" id="sage" type="text" class="form-control" placeholder="请输入上传人">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="saddress" class="col-sm-2 control-label">家庭住址</label>
                            <div class="col-sm-10">
                                <input v-model="new_stu.saddress" id="saddress" type="text" class="form-control" placeholder="请输入上传人">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="semail" class="col-sm-2 control-label">Email:</label>
                            <div class="col-sm-10">
                                <input v-model="new_stu.semail" id="semail" type="text" class="form-control" placeholder="请输入上传人">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" @click="hideModal()">关闭</button>
                    <button class="btn btn-primary" @click="saveBook">保存</button>
                </div>
            </div>
        </div>
    </div>

</div>




</body>
<script type="text/javascript">
    var vm=new Vue({
        el:"#vuebox",
        data:{
            stuList:{},
            delResult:{},
            new_stu:{sid:'',sname:'',sgender:'',sage:'',saddress:'',semail:''},
        },methods:{
            select:function(){
                axios.get("/select").then(res=>{this.stuList=res.data});
            },
            //    添加图书,显示模态框
            addBook:function () {
                $('#mymodal').modal('show');
            },
            //    隐藏模态框
            hideModal:function () {
                $("#mymodal").modal('hide');
                //调用清空模态框的方法
                this.clearForm();
            },
            //    清空模态框内容
            clearForm:function () {
                $("#sid").val();
                $("#sname").val('');
                $("#sgender").val('');
                $("#sage").val('');
                $("#saddress").val("");
                $("#semail").val("");
            },
            //新增图书信息
            saveBook:function () {
                axios.post("/add",this.new_stu).then(res=>{
                    this.delResult=res.data;
                       this.hideModal();
                       this.select();
                })
            },
            to_update_stu:function (sid) {
                axios.get("/selectById",{params:{sid:sid}}).then(res=>{
                    this.new_stu=res.data.data;
                      $("#mymodal").modal('show');
                })
            }
        },
        mounted(){
            this.select();
        },

    })
</script>
</html>